<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit>
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <div class="table-operator">
            <rx-button alias="formOnlyOfficeAdd" :butn-icon="'plus'" :butn-type="'primary'" :show-no-right="true" @click="addDoc">{{$ti18('rxList.addBtn','新建')}}</rx-button>

          </div>
          <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
        </div>
        <div slot="searchbar" btnalign="right"  v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
          <a-form layout="vertical">
                <a-form-item label="EXT_NAME_">
                    <a-input :placeholder="$ti18('rxDecorator.input','请输入')+'EXT_NAME_'" v-model="queryParam.Q_EXT_NAME__S_LK"/>
                </a-form-item>
                <a-form-item label="FILENAME_">
                    <a-input :placeholder="$ti18('rxDecorator.input','请输入')+'FILENAME_'" v-model="queryParam.Q_FILENAME__S_LK"/>
                </a-form-item>
          </a-form>
        </div>
        <rx-grid
                ref="table"
                :allowRowSelect="true"
                :multiSelect="true"
                :columns="columns"
                :defaultPageSize="10"
                url="/api-form/form/onlyoffice/formOnlyOffice/query"
                :queryParam="queryParam"
                data-field="result.data"
                :pageSizeOptions="['10','30','40']"
                id-field="id"
                @selectChange="onSelectChange"
        >
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                    <span  @click="editDoc(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                    <span  @click="delByDocId(record.docId)">{{$ti18('rxList.delBtn','删除')}}</span>
          </span>
        </rx-grid>
      </rx-fit>
        <a-modal v-model="visible" :title="i18n('list.addDoc','添加文档')" @ok="handleOk">
            <a-form-model :model="form" >
                <a-form-model-item :label="i18n('form.filename','文件名')">
                    <a-input v-model="form.name" />
                </a-form-model-item>
                <a-form-model-item :label="i18n('list.docType','文档类型')">
                    <a-select default-value="docx"
                              v-model="form.type" :options="types"
                              :getPopupContainer="p=>p.parentNode"
                    ></a-select>
                </a-form-model-item>
            </a-form-model>
        </a-modal>
    </div>
  </rx-layout>
</template>

<script>
  import FormOnlyOfficeApi from '@/api/form/onlyoffice/formOnlyOffice'
  import FormOnlyOfficeEdit from './FormOnlyOfficeEdit'
  import {BaseList,RxFit,RxGrid,Util } from "@lowcode/jpaas-common-lib";
  import OnlyOfficeDemo from "@/views/modules/form/onlyoffice/OnlyOfficeDemo";
  export default {
    name: 'FormOnlyOfficeList',
    mixins: [BaseList],
    components: {
      RxFit
    },
    data() {
      return {
        columns: [
          {
            title: this.$ti18('rxList.index','序号'),
            type: 'indexColumn',
            width: 40,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
          {title: this.i18n('form.docId','文档ID'), dataIndex: 'docId', width: 100},
          {title: this.i18n('form.filename','文件名'), dataIndex: 'filename', width: 100},
          {title: this.i18n('form.extName','扩展名'), dataIndex: 'extName', width: 100},
          {title: this.i18n('form.fileKey','文件KEY'), dataIndex: 'key', width: 100},
          {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
        ],
        component:FormOnlyOfficeEdit,
        comment:"FORM_ONLYOFFICE",
        widthHeight:['800px','600px'],
        fitSearch:false,

          visible:false,
          form:{
            name:"",
            type:"docx"
          },
          types:[
              {label:"docx",value:"docx"},
              { label:"xlsx",value:"xlsx"},
              { label:"pptx",value:"pptx"}]
      }
    },
    methods:{
      i18n(name,text,key){
          return this.$ti18(name,text,"FormOnlyOffice",key);
      },
      i18nInput(name,text,key){
          return this.$ti18(name,text,"FormOnlyOffice",key);
      },
      delByDocId(docId){
          let self_=this;
          this.$confirm({
              title: self_.$ti18('rxMsa.actionTips','操作提示'),
              zIndex: 20000,
              content: self_.$ti18('rxMsa.delInfo','您确定需要删除选中的记录吗？'),
              okText: self_.$ti18('rxForm.ackBtn','确认'),
              cancelText: self_.$ti18('rxForm.cancelBtn','取消'),
              onOk() {
                  FormOnlyOfficeApi.delByDocId(docId).then(res=>{
                      if (res.success) {
                          self_.refreshGrid()
                      }
                  });
              },
              onCancel() {
              }
          })

      },
      addDoc(){
            this.visible=true;
      },
      handleOk(){
          let self_=this;
          FormOnlyOfficeApi.create(this.form)
              .then(res=>{
                  let docId= res.message;
                  this.visible=false;

                  Util.open({
                      component: OnlyOfficeDemo,
                      curVm: self_,
                      max:true,
                      title: "OnlyOffice",
                      data: {
                          docId: docId,
                      }
                  }, function (action) {

                  })
              })

          //
      },
      editDoc(record){
          Util.open({
              component: OnlyOfficeDemo,
              curVm: this,
              max:true,
              title: "OnlyOffice",
              data: {
                  docId: record.docId,
              }
          }, function (action) {
          })
      }

    }
  }
</script>
<style scoped>
  .table-operator {
    padding:4px;
  }
  .table-operator button {
    margin:2px;
  }
</style>

